package com.hh.utility;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Locale;

import android.util.Log;

import com.hh.droid.HhDroid;


/**
 * Date format
 * YYYY-MM-DD
 * YYYY-MM-DD HH:MM
 * YYYY-MM-DD HH:MM:SS
 * YYYY-MM-DD HH:MM:SS.SSS
 * HH:MM
 * HH:MM:SS
 * HH:MM:SS.SSS
 * @author wajdihh
 *
 */

public class PuDate{

	/**
	 * Format : dd/MM/yyyy
	 */
	public static final String FORMAT_DATE_FR = "dd/MM/yyyy";
	/**
	 * Format : MM/dd/yyyy
	 */
	public static final String FORMAT_DATE_EN = "MM/dd/yyyy";
	/**
	 * Format : dd/MM/yyyy HH:mm:ss
	 */
	public static final String FORMAT_DATETIME_FR = "dd/MM/yyyy HH:mm:ss";
	/**
	 * Format : MM/dd/yyyy HH:mm:ss
	 */
	public static final String FORMAT_DATETIME_EN = "MM/dd/yyyy HH:mm:ss";
	
	private String _mDateStringFormat;
	private SimpleDateFormat _mDateFormater;

	{
		_mDateStringFormat="yyyy-MM-dd";
	}

	public int month;
	public int day;
	public int year;
	public int hour;
	public int minute;
	public int second;

	public PuDate(){
		_mDateFormater=new SimpleDateFormat(_mDateStringFormat,getLocal());
	}

	public PuDate(int month, int day, int year) {
		super();
		this.month = month;
		this.day = day;
		this.year = year;
	}

	public PuDate(int month, int day, int year, int hour, int minute,int second) {
		super();
		this.month = month;
		this.day = day;
		this.year = year;
		this.hour = hour;
		this.minute = minute;
		this.second = second;
	}

	public Locale getLocal(){
		return Locale.getDefault();
	}

	public String getDateStringFormat() {
		return _mDateStringFormat;
	}

	public void setDateStringFormat(String _mDateStringFormat) {
		this._mDateStringFormat = _mDateStringFormat;
		_mDateFormater.applyPattern(_mDateStringFormat);
	}

	public SimpleDateFormat getDateFormater() {
		return _mDateFormater;
	}

	public void setDateFormater(SimpleDateFormat _mDateFormater) {
		this._mDateFormater = _mDateFormater;
	}
	
	/**
	 * Static
	 */
	
	public static long getTimeFromStringDate(String pDateString){
		long lTime=-1;
		try {
			lTime= HhDroid.getInstance().mDateFormat.parse(pDateString).getTime();
		} catch (ParseException e) {
			e.printStackTrace();
			Log.e("pUDate.getTimeFromStringDate", "Parse date incorrect");
			lTime=-1;
		}
		return lTime;
	}
	
	public static String getStringFromDate(long pDateTime){	
		return HhDroid.getInstance().mDateFormat.format(pDateTime);
	}
}
